<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客正文</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/blog_content.css">
	
    <link rel="stylesheet" href="editor.md/css/editormd.preview.min.css" />
    <script src="js/jquery.min.js"></script>
    <script src="editor.md/editormd.js"></script>
    <script src="editor.md/lib/marked.min.js"></script>
    <script src="editor.md/lib/prettify.min.js"></script>

    <script src="js/urlutils.js"></script>
	<script src="js/logout.js"></script>

</head>
<body>
    <div class="nav">
        <div class="flag">
            <img src="image/face2.png" alt="logo">
            <div class="title">我的博客系统</div>
        </div>

        <div class="page">
            <a href="blog_list.html">主页</a>
			<a href="myblog_list.html">内容管理</a>
            <a href="blog_add.html">写博客</a>
            <a href="javascript:logout()">注销</a>
        </div>
    </div>
    
    <div class="container">
        <div class="left">
            <div class="card">
                <img src="image/face2.png" alt="face" id="photo">
                <h3 id="username">不摸鱼的程序员</h3>
                <a href="https://gitee.com/">gitee地址</a>
                <div class="conter">
                    <span>文章</span>
                </div>
                <div class="conter">
					<span id="artcount">0</span>
                </div>
            </div>
        </div>
        <div class="right">
            <div class="blog">
			   <!-- 博客标题 -->
			   <h3 id="title"></h3>
			   <!-- 博客时间 -->
			   <div class="date">
				   发布时间：<span id="createtime"></span>
				   |
				   阅读量：<span id="rcount"></span>
			   </div>
			   <!-- 博客正文 -->
			   <div id="editorDiv">

			   </div>
            </div>
        </div>
    </div>
	<script type="text/javascript">
	        var aid = getParamValue("aid");
	        var editormd;
	        function initEdit(md){
	            editormd = editormd.markdownToHTML("editorDiv", {
	            markdown : md, // Also, you can dynamic set Markdown text
	            // htmlDecode : true,  // Enable / disable HTML tag encode.
	            // htmlDecode : "style,script,iframe",  // Note: If enabled, you should filter some dangerous HTML tags for website security.
	            });
	        }
	
	        // 初始化页面（将用户信息和文章信息显示到页面上）
	        function init() {
	            // 1.校验参数
	            if (aid == null || aid <= 0) {
	                alert("参数错误!");                
	                return false;
	            }
	            // 2.向后端请求数据
	            jQuery.ajax({
	                url:"/art/detail",
	                type:"GET",
	                data:{
	                    "aid":aid
	                },
	                success:function(res) {
	                    // 3.将数据展示给用户
	                    if (res.code == 200 && res.data != null) {
	                        // 获取文章信息
	                        var art = res.data.art;
	                        if (art != null) {
	                            jQuery("#title").html(art.title);
	                            jQuery("#createtime").html(art.createtime);
	                            jQuery("#rcount").html(art.rcount);
	                            initEdit(art.content);;
	                        } else {
	                            alert("查询失败:"+res.meg);
	                        }
	
	                        // 获取用户信息
	                        var user = res.data.user;
	                        if (user != null) {
	                            if (user.photo != "") {
	                                jQuery("#photo").attr("src",user.photo);
	                            }
	                            jQuery("#username").html(user.username);
	                            jQuery("#artcount").html(user.artCount);
	                        } else {
	                            alert("查询失败:"+res.meg);
	                        }
	
	                    } else {
	                        alert("查询失败:"+res.meg);
	                    }
	                }
	            });
	
	        }
	        init();
	
	        // 动态访问量
	        function increase_rcount() {
	            // 1.校验参数
	            if (aid == null || aid <= 0) {
	                return false;
	            }
	            // 2.请求后端
	            jQuery.ajax({
	                url:"/art/incre_rcount",
	                type:"GET",
	                data:{
	                    "aid":aid
	                },
	                success:function(res) {}
	            });
	        }
	        increase_rcount();
	    </script> 
</body>
</html>